#include "camera.h"
#include "windows-mac.h"
#include <cmath>

Camera::Camera()
{
	x = 0;
	y = 0;
	z = 10;
	
	tx = 0;
	ty = 0;
	tz = 0;
	
	phi = 0;
	teta = 0;
	
	for(int i=0;i<SDLK_LAST;i++)
	{
		keyboard[i] = false;
	}
}

void Camera::keyDown(SDLKey key)
{
	keyboard[key] = true;
}

void Camera::keyUp(SDLKey key)
{
	keyboard[key] = false;
}

void Camera::animate(Uint32 time)
{
	if(keyboard[SDLK_z])
	{
		this->z -= 0.02 * (double)time;
		this->tz -= 0.02 * (double)time;
	}
	
	if(keyboard[SDLK_s])
	{
		this->z += 0.02 * (double)time;
		this->tz += 0.02 * (double)time;
	}
	
	if(keyboard[SDLK_q])
	{
		this->x -= 0.02 * (double)time;
		this->tx -= 0.02 * (double)time;
	}
	
	if(keyboard[SDLK_d])
	{
		this->x += 0.02 * (double)time;
		this->tx += 0.02 * (double)time;
	}
	
	if(keyboard[SDLK_SPACE])
	{
		if(!keyboard[SDLK_LSHIFT])
		{
			this->y += 0.02 * (double)time;
			this->ty += 0.02 * (double)time;
		}
		else
		{
			this->y -= 0.02 * (double)time;
			this->ty -= 0.02 * (double)time;
		}
	}
	
	if(keyboard[SDLK_RIGHT])
	{
		this->teta += 0.01 * (double)time;
		this->tx = x + cos(teta*M_PI/180) * cos(phi*M_PI/180);
		this->tz = z + cos(teta*M_PI/180) * sin(phi*M_PI/180);
		this->ty = y + sin(phi*M_PI/180);
		
		std::cout << teta << "\n";
	}
}

void Camera::look()
{
	gluLookAt(x, y, z, tx, ty, tz, 0, 1, 0);
}